package app.netant.book.bxwx;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
import app.netant.book.base.BaseEntity;
import app.netant.book.base.BasePage;
import cn.lily.com.enviroment.Enviroment;

public class BxwxPage extends BasePage {

	public BxwxPage(String netSite) {
		super(netSite);
		this.tableKey = "bxwx";
		this.selectKey = "#wrap #center #results .result-list .result-item .result-game-item-detail .result-item-title a.result-game-item-title-link";
		this.preHref = "https://www.bxwx.la";
	}

	@Override
	public String buildHref(Element element) {	
		String href = element.attr("href");
		if(href.startsWith("/")){
			href = this.preHref + href;
		}
		
		String tmp = href.substring(0,href.length()-1);
		int idx = tmp.lastIndexOf("/");
		int idx2 = tmp.lastIndexOf("/", idx-1);
		
		String tmpUrl = tmp.substring(idx2);
		String url = "https://www.bxwx.la/binfo"+tmpUrl+".htm";
		
		
		return url;
	}

	@Override
	public BaseEntity buildEntity() {
		return new BxwxEntity();
	}

	@Override
	public BaseDetail buildDetail(String href) {
		return new BxwxDetail(href);
	}

	@Override
	public void afterEntity(BaseEntity entity, Element element) {
		
	}
	
	public static void main(String[] args) {
		Enviroment.createEnv();
		Enviroment.getEnv().getLogBean().beginLog();
		BxwxPage page = new BxwxPage("http://zhannei.baidu.com/cse/search?q=&p=3&s=756366825763876368&nsid=");
		page.analyseHref();
	}
	
}
